package com.xpalive.common.helper.gson;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;

public class ClassExclusionStrategyHelper implements ExclusionStrategy {
	private Map<String, String> classMap = new HashMap<String, String>();
	private boolean excludeClass;
	
	

	public ClassExclusionStrategyHelper(Class<?>[] clazzes, boolean excludeClass) {
		this.excludeClass = excludeClass;
		for (Class<?> clazz : clazzes) {
			classMap.put(clazz.getName(), clazz.getName());
		}
	}
	@Override
	public boolean shouldSkipField(FieldAttributes f) {
		return false;
	}

	@Override
	public boolean shouldSkipClass(Class<?> clazz) {
		if(hasKey(clazz.getName())){
			return excludeClass;
		}else{
			return !excludeClass;
		}
	}
	
	private boolean hasKey(String fileName) {
		return StringUtils.isBlank(this.classMap.get(fileName));
	}

}
